home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Telnet 2.6.1d1 4⁄26⁄94 Folder / source / main / mainseg.c < prev    next >
C/C++ Source or Header  |  1994-02-20  |  4KB  |  148 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1992,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. ****************************************************************/
  13.  
  14. #ifdef MPW
  15. #pragma segment main
  16. #endif
  17.  
  18. #define GLOBALMASTER            /* Global structures are charged to us... see below */
  19. #include "TelnetHeader.h"
  20. #include "event.proto.h"
  21. #include "netevent.proto.h"
  22. #include "init.proto.h"
  23. #include "network.proto.h"        // For netshut proto
  24. #include "dnr.proto.h"            // For CloseResolver proto
  25. #include "wind.h"
  26. #include "MacBinary.h"
  27. #include "binsubs.proto.h"            // For close_mb_files proto
  28.  
  29. #include "vgtek.proto.h"        // For TEKMAINunload proto
  30. #include "vr.h"                    // So vr.proto.h works (sigh)
  31. #include "vr.proto.h"            // For ICRunload proto
  32. #include "rsmac.proto.h"        // For RSunload proto
  33. #include "vsem.proto.h"            // For VSunload proto
  34. #include "configure.proto.h"    // For CONFIGUREunload proto
  35. #include "macros.proto.h"        // For MACROSunload proto
  36. #include "bkgr.proto.h"            // For FTPServerUnload proto
  37. #include <Printing.h>            // So printing.proto.h doesn't die
  38. #include "printing.proto.h"        // For PrintingUnload proto
  39. #include "sets.proto.h"            // For SETSunload proto
  40. #include "ftpbin.proto.h"        // For FTPClientunload proto
  41. #include "rg0.proto.h"            // For TEKNULLunload proto
  42. #include "rgmp.proto.h"            // For TEKMacPicunload proto
  43. #include "maclook.proto.h"        // For MiscUnload proto
  44.  
  45. #include "mainseg.proto.h"
  46.  
  47. //#define    PERFORMANCE                    //    Define to use MPW performance tools
  48. #ifdef    PERFORMANCE
  49. #include    <Perf.h>
  50. TP2PerfGlobals    ThePGlobals;
  51. #endif
  52.  
  53. Cursor *theCursors[NUMCURS];        /* all the cursors in a nice bundle */
  54.  
  55. WindRec
  56.     *screens,        /* Window Records (VS) for :    Current Sessions */
  57.     *ftplog;
  58.  
  59. short scrn=0;
  60.  
  61. TelInfoRec    *TelInfo;            /* This is defined here and externed everywhere else. */
  62.  
  63. main(void)
  64. {
  65.     short    i;
  66.     long    lastCount = 0;
  67.     MaxApplZone();
  68.     
  69.     for (i=0; i<9; i++)
  70.         MoreMasters();
  71.  
  72. #ifdef    PERFORMANCE
  73.     ThePGlobals = nil;
  74.     if (!InitPerf(&ThePGlobals, 10, 8, TRUE, TRUE, "\pCODE", 0, "\p", FALSE, 0, 0, 0))
  75.         Debugger();
  76.     PerfControl(ThePGlobals, TRUE);
  77. #endif
  78.  
  79.     init();                    /* JMB 2.6 - Call all init routines */
  80.     UnloadSeg(&init);        /* Bye, bye to init routines...     */
  81.  
  82.     do {                        /* BYU - Do this forever */
  83.         UnloadSegments();
  84.         DoEvents();
  85.         if (!TelInfo->done) DoNetEvents();
  86.         if (TickCount() - lastCount > 1800) {            // Once every 30 seconds
  87.             CheckFreeMemory();
  88.             lastCount = TickCount();
  89.             }
  90.         } while (!TelInfo->done);                        /* BYU mod */
  91.         
  92. #ifdef    PERFORMANCE
  93.     if (!PerfDump(ThePGlobals, "\pPerform.out", TRUE, 80))
  94.         DebugStr("\pDump Failed");
  95.     Debugger(); 
  96.     TermPerf(ThePGlobals);
  97. #endif
  98.  
  99. }
  100.  
  101. void    quit( void)
  102. {
  103.     if (TelInfo->numwindows>0)
  104.         return;
  105.  
  106.     netshut();
  107.     CloseResolver();            /* BYU 2.4.16 */
  108.  
  109.     close_mb_files();            /* BYU - Don't leave any files open! */
  110.     TelInfo->done = 1;            /* BYU */
  111. }
  112.  
  113. void    forcequit(void)
  114. {
  115.     quit();
  116.     ExitToShell();
  117. }
  118.  
  119. //    This is rather simple right now, but I'll make it smarter when I have the time.
  120. void    CheckFreeMemory(void)
  121. {
  122.     long    space, block;
  123.     
  124.     PurgeSpace(&space, &block);
  125.     
  126.     if (space < (30 * 1024))
  127.         Alert(MemoryLowAlert, NULL);
  128. }
  129.  
  130. //    This unloads the segments that are safe to unload.  Right now, the DNR and network
  131. //    segments ARE NOT safe to unload.  Do _not_ add anything to this unless you really
  132. //    know what you are doing!  (I MEAN IT!)
  133. void    UnloadSegments(void)
  134. {
  135.     UnloadSeg(&TEKMAINunload);
  136.     UnloadSeg(&ICRunload);
  137.     UnloadSeg(&RSunload);
  138.     UnloadSeg(&VSunload);
  139.     UnloadSeg(&CONFIGUREunload);
  140.     UnloadSeg(&MACROSunload);
  141.     UnloadSeg(&FTPServerUnload);
  142.     UnloadSeg(&PrintingUnload);
  143.     UnloadSeg(&SETSunload);
  144.     UnloadSeg(&FTPClientunload);
  145.     UnloadSeg(&TEKNULLunload);
  146.     UnloadSeg(&TEKMacPicunload);
  147.     UnloadSeg(&MiscUnload);
  148. }